package com.my.test.thread.atomic;

import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;

public class TestAtomicIntegerFieldUpdater2 {

    public static void main(String[] args) {
        // 原子更新引字段类
        AtomicIntegerFieldUpdater<User> a = AtomicIntegerFieldUpdater.
                newUpdater(User.class, "old");

        // 柯南15岁
        User user = new User("conan",15);
        System.out.println(a.getAndIncrement(user));
        System.out.println(a.get(user));

    }

    public static class User {
        private String name;
        public volatile int old;

        public User(String name, int old) {
            super();
            this.name = name;
            this.old = old;
        }
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public int getOld() {
            return old;
        }
        public void setOld(int old) {
            this.old = old;
        }
    }
}
